import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
// import 'element-ui/lib/theme-default/index.css'
import 'element-ui/lib/theme-chalk/index.css';
//import './assets/theme/theme-green/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import routes from './routes'
// import Mock from './mock'
import axios from 'axios';
// Mock.bootstrap();
import 'font-awesome/css/font-awesome.min.css'
import VueI18n from 'vue-i18n'

Vue.use(VueI18n) // 通过插件的形式挂载
Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)

//NProgress.configure({ showSpinner: false });



Vue.prototype.$http = axios
//公共前缀,只要是axios请求，在请求上都加/api
// axios.defaults.baseURL = "/api";
axios.defaults.baseURL = "http://localhost";
const router = new VueRouter({
  mode: 'history',
  routes
})
const i18n = new VueI18n({
  locale: 'zh-CN',    // 语言标识
  //this.$i18n.locale // 通过切换locale的值来实现语言切换
  messages: {
    'zh-CN': require('./common/lang/zh'),   // 中文语言包
    'en-US': require('./common/lang/en')    // 英文语言包
  }
})

//路由拦截器
/*router.beforeEach((to, from, next) => {
  //NProgress.start();
  if (to.path == '/login') {
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})*/

//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
  //el: '#app',
  //template: '<App/>',
  i18n,
  router,
  store,
  //components: { App }
  render: h => h(App)    //template: '<App/>',components: { App }  使用app组件
}).$mount('#app')   //跟el: '#app'  一样挂载

